<?php
class App_Module_Admin_Component_Media_Ctrl_Http_Ajax extends App_Module_Admin_Component_Media_Ctrl_Http
{
    public function get_media_filePrAction()
    {
    	$file = $this->GetMediaFromQueryId();

      	if ($file)
      	{
			Mozg::Response('http')->SetBody($file->ExportData());
      	}
      	else
      	{
      		Mozg::Lib('messanger')->createMessage(Mozg_Lang::_('MEDIA_FILE_NOT_FOUND'), MESSAGE_ERROR);
      		Mozg::Response('http')->SetStatus(Mozg_Response::StatusError);
      	}
    }

    public function get_media_contentPrAction()
    {
    	$file = $this->GetMediaFromQueryId();

      	if ($file)
      	{
			Mozg::Response('http')->SetBody($this->GetTpl('Media')->Get($file));
      	}
      	else
      	{
      		Mozg::Lib('messanger')->createMessage(Mozg_Lang::_('MEDIA_FILE_NOT_FOUND'), MESSAGE_ERROR);
      		Mozg::Response('http')->SetStatus(Mozg_Response::StatusError);
      	}
    }

    public function savePrAction ()
    {
    	if (!Mozg::Request('http')->getQuery('upload')) return;

       	$file = $this->GetMediaFromQueryId();
   		if (!$file) $file = Mozg_Mapper::Get('Media')->GetEntity();

		$uploader = new Mozg_AjaxFileUploader($file, $this->GetTpl('Editform'));
		Mozg::Response('http')->SetBody($uploader->Upload());
		Mozg::Layout('admin')->SetTemplate('simple');
    }
}